var back = document.querySelector(".goback");
back.addEventListener("click", () => {
  history.go(-1);
});
var toSou = document.querySelector(".toSou");
var inSou = document.querySelector(".inSou");
var ta = document.querySelector(".ta");
var ul = document.querySelector(".ul");
inSou.focus()
inSou.addEventListener("keyup", ulList);
inSou.addEventListener("click", ulList);
function weather(data) {
  for (let i = 0; i < 10; i++) {
    ul.children[i].innerHTML = data["g"][i].q;
  }
}
function ulList() {
  var val = inSou.value;
  var script = document.createElement("script");
  script.src = `https://www.baidu.com/sugrec?pre=1&p=3&ie=utf-8&json=1&prod=pc&from=pc_web&sugsid=31253,33849,33759,26350,33811&wd=${val}&csor=3&pwd=r%27r%27r&cb=weather`;
  document.body.appendChild(script);
  if (inSou.value.trim() == "") {
    for (let i = 0; i <10; i++) {
      ul.children[i].innerHTML = "";
    }
  }
}

toSou.addEventListener("click", function () {
  var input = inSou.value.trim();
  if (input) {
    open("https://www.baidu.com/s?wd=" + input, "_self");
  }
});
ul.addEventListener(
  "click",
  function (e) {
    if (e.target.nodeName.toLowerCase() == "li") {
      open("https://www.baidu.com/s?wd=" + e.target.innerHTML.trim(), "_self");
    }
  },
  false
);
document.addEventListener('keyup', e => {
  if (e.keyCode == 13) {
    var input = inSou.value.trim();
  if (input) {
    open("https://www.baidu.com/s?wd=" + input, "_self");
  }
  }
})